package me.zachwhaley.android.utils;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.EditText;

public final class AlertDialogs
{
	public interface AlertCallBacks
	{
		abstract void positiveButtonPressed();
		abstract void negativeButtonPressed();
	}

	public interface InputCallBacks
	{
		abstract void positiveButtonPressed(String text);
		abstract void negativeButtonPressed(String text);
	}
	
	public static void showAlertDialog(Context context, String title, String yes, String no, final AlertCallBacks callback)
	{
		showInfoDialog(context, title, null, yes, no, callback);
	}
	
	public static void showInfoDialog(Context context, String title, String message, String yes, String no, final AlertCallBacks callback)
	{
		if (yes == null)
			yes = "OK";
		if (no == null)
			no = "Cancel";
		AlertDialog.Builder alert = new AlertDialog.Builder(context)
		.setTitle(title);
		if (message != null)
			alert.setMessage(message);
		alert.setPositiveButton(yes, new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int which)
			{
				callback.positiveButtonPressed();		
			}
		})
		.setNegativeButton(no, new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int which)
			{	
				callback.negativeButtonPressed();
			}
		})
		.show();
	}
	
	public static void showInputDialog(Context context, String title, String yes, String no, final InputCallBacks callback)
	{
		if (yes == null)
			yes = "OK";
		if (no == null)
			no = "Cancel";
		
		final EditText input = new EditText(context);
		input.requestFocus();
		new AlertDialog.Builder(context)
		.setTitle(title)
		.setView(input)
		.setPositiveButton(yes, new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int which)
			{
				callback.positiveButtonPressed(input.getText().toString());
			}
		})
		.setNegativeButton(no, new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int which)
			{	
				callback.negativeButtonPressed(input.getText().toString());
			}
		})
		.show();
	}
	
	public static void showListDialog(Context context, String title, CharSequence[] list, DialogInterface.OnClickListener listener)
	{
		new AlertDialog.Builder(context)
		.setTitle(title)
		.setItems(list, listener)
		.show();
	}
}
